check_and_install_package() {
###
 # @Date: 2025-04-14 11:17:05
### 
    # 参数检查
    if [ $# -ne 1 ]; then
        echo "Usage: ${FUNCNAME[0]} <package_name>"
        return 1
    fi

    local pkg="$1"
    local distro_id=""
    local install_cmd=""
    local check_cmd=""

    # 检测发行版
    if [ -f /etc/os-release ]; then
        distro_id=$(grep -w ID /etc/os-release | cut -d= -f2 | tr -d '"')
    elif type lsb_release >/dev/null 2>&1; then
        distro_id=$(lsb_release -si | tr '[:upper:]' '[:lower:]')
    else
        echo "无法检测Linux发行版!"
        return 2
    fi

    # 定义各发行版安装命令
    case "$distro_id" in
        debian|ubuntu|raspbian)
            check_cmd="dpkg -l"
            install_cmd="sudo apt-get install -y"
            ;;
        centos|rhel|fedora|ol)
            if [ "$distro_id" = "fedora" ]; then
                install_cmd="sudo dnf install -y"
            else
                install_cmd="sudo yum install -y"
            fi
            check_cmd="rpm -q"
            ;;
        arch|manjaro)
            check_cmd="pacman -Q"
            install_cmd="sudo pacman -S --noconfirm"
            ;;
        opensuse*|sled|sles)
            check_cmd="rpm -q"
            install_cmd="sudo zypper install -y"
            ;;
        alpine)
            check_cmd="apk info -e"
            install_cmd="sudo apk add"
            ;;
        *)
            echo "不支持的发行版: $distro_id"
            echo "支持列表: Debian, Ubuntu, RHEL, CentOS, Fedora, Arch, openSUSE, Alpine"
            return 3
            ;;
    esac

    # 检查是否已安装
    if $check_cmd "$pkg" >/dev/null 2>&1; then
        # echo "[$distro_id] 包已安装: $pkg"
        return 0
    fi

    echo "[$distro_id] 正在安装 $pkg..."
    if ! $install_cmd "$pkg"; then
        echo "安装失败! 请检查:"
        echo "1. 包名称是否正确 (不同发行版可能不同)"
        echo "2. 网络连接是否正常"
        echo "3. 软件源配置是否正确"
        return 4
    fi

    echo "安装完成: $pkg"
    return 0
}
 定义 JSON 解析函数
get_json() {
    local json_data="$1"
    local key="$2"
    echo "$json_data" | python3 -c "import sys,json; print(json.load(sys.stdin)['$key'])"
}

echo "工具箱启动"
# 前置条件检查start

check_and_install_package wget
check_and_install_package curl
check_and_install_package python3  

# 获取 JSON 数据并存储到变量
data=$(curl -s https://gitee.com/ji_pu/personal-linux-toolbox/raw/master/data.json)

# 解析数据
URL=$(get_json "$data" "url")
echo "解析结果：$URL"